<?php
/**
 * @file bg-top.php
 * @version 0.1
 * @desc 输出买入、卖出TOP值，输出XML
 */

$action = $_POST['action'];

if ($action == 'getTop'){

header("Content-Type:text/html;charset=UTF-8");
require_once config.php;
$conn = &ADONewConnection('mysql');
$conn->debug = false;

$conn->Connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // or die( $conn->ErrorMsg() ); 
$conn->Execute('SET NAMES UTF8');

echo "<response>";

// 卖出
$query4 = "SELECT `price` , `num`
			FROM `bus_top`
			WHERE `flag` = '4'
			ORDER BY price DESC";
$ADODB_FETCH_MODE = ADODB_FETCH_ASdSOC;
//$re = $conn->Execute('CALL top(4,5,5 )');
//var_dump($re);
$re = $conn->Execute($query4);
if (!$re) echo $conn->ErrorMsg(); 
else {
	while (!$re->EOF){
		echo "<sell><price>{$re->fields['price']}</price><num>{$re->fields['num']}</num></sell>";
		//echo "{$re->fields['price']}  +  {$re->fields['num']}<br />";
		$re->MoveNext();
	}
}


// 买入
$query3 = "SELECT `price` , `num`
			FROM `bus_top`
			WHERE `flag` = '3'
			ORDER BY price DESC";
$ADODB_FETCH_MODE = ADODB_FETCH_ASdSOC;
//$re = $conn->Execute('CALL top(4,5,5 )');
//var_dump($re);
$re = $conn->Execute($query3);
if (!$re) echo $conn->ErrorMsg(); 
else {
	while (!$re->EOF){
		echo "<buy><price>{$re->fields['price']}</price><num>{$re->fields['num']}</num></buy>";
		//echo "{$re->fields['price']}  +  {$re->fields['num']}<br />";
		$re->MoveNext();
	}
}

echo "</response>";	
} //END if getTop
?>